﻿Imports Mystery
Public Class ContentPropertyColumnAttr
    Inherits ContentPropertBaseIOAttr

    Private _label As String

    Public Property filter_control As Type

    Property label As String
        Get
            If String.IsNullOrEmpty(_label) Then
                setUpLabel()
            End If
            Return _label
        End Get
        Set(value As String)
            _label = value
        End Set
    End Property

    Private Sub setUpLabel()
        'either a content property or reference
        If String.IsNullOrEmpty(_label) Then 'we use the same as this property
            Dim cp As ContentProperty = Me.used_in.getMysteryAttribute(Of ContentProperty)()
            If cp IsNot Nothing Then
                _label = cp.label
            Else
                Dim cr As ContentReference = Me.used_in.getMysteryAttribute(Of ContentReference)()
                _label = cr.label
            End If
        End If
    End Sub

    Private _filter_activator As IActivator

    Public Overrides Sub setUp()
        MyBase.setUp()
        If filter_control IsNot Nothing Then
            _filter_activator = getGlobalObject(Of FastActivator).getActivator(filter_control)
        End If
    End Sub

    Public Function instanceFilter() As UserControl
        If _filter_activator Is Nothing Then Return Nothing
        Dim result As UserControl = _filter_activator.createInstance
        If TypeOf (result) Is IPropertyFilterControl Then
            Dim pfc As IPropertyFilterControl = result
            pfc.content_property = Me.used_in
        End If
        Return result
    End Function

End Class

